<!-- hoanglinhkd -->
<script type="text/javascript" src="user.js"></script>

<?php 
	include_once('class_nguoiban.php');
	include_once('library/MailPackage/sendmail.php');
	include_once('components/nguoiban/class_nguoiban.php');
	
?> 

<?php
	//--------------------------------------------//
	define ("MAX_SIZE","1024"); 
	
	function getExtension($str) {
		 $i = strrpos($str,".");
		 if (!$i) { return ""; }
		 $l = strlen($str) - $i;
		 $ext = substr($str,$i+1,$l);
		 return $ext;
	}
	
	$errors=0;
	
	if(isset($_POST['Submit'])) 
	{
		$image=$_FILES['upHinhAnh']['name'];
	
		if ($image) 
		{
			$filename = stripslashes($_FILES['upHinhAnh']['name']);
			$extension = getExtension($filename);
			$extension = strtolower($extension);
		
			if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) 
			{
				echo '<h1>Không phải file ảnh (các file có hổ trợ: *.jpg,*.jpeg,*.png,*.gif)!</h1>';
				$errors=1;
			}
			else
			{
				$size=filesize($_FILES['upHinhAnh']['tmp_name']);
	
				if ($size > MAX_SIZE*1024)
				{
					echo '<h1>Kích thước quá lớn (size file < 1MB)!</h1>';
					$errors=1;
				}
				move_uploaded_file($_FILES["upHinhAnh"]["tmp_name"],"../images/nguoiban/" . $_FILES["upHinhAnh"]["name"]);
				$hinhanh = $_FILES['upHinhAnh']['name'] ;
				//echo 'Stored in: ' . '../data/pic_san_pham/' . $_FILES['image']['name'];
			}
		}
		else
		{
				$flag = 0 ;
				$smg_img = 'Lỗi khi upload file hình ảnh !';
		}
	}
	if(isset($_POST['Submit']) && !$errors) 
	{
		echo "<h3 align='left' style='color:Blue'>Uploaded ảnh thành công</h3>";
	}

	//--------------------------------------------//
	
	function CapNhatVaoCSDL()
	{
		$username = $_REQUEST['$username'];
		$hoten = $_REQUEST['hoten'];
		$ngaysinh = $_REQUEST['ngaysinh'];		
		$diachi = $_REQUEST['diachi'];
		$dienthoai = $_REQUEST['dienthoai'];
		$gioitinh = $_REQUEST['gioitinh'];
		$hinhanh = $_REQUEST['hinhanh'];
		$doihinh = $_REQUEST['doihinh'];
		$hinhanh="/../images/nguoiban/".$hinhanh;
		
		if($doihinh == 1)
		{
			$hinhanh = "images/thanhvien/".$hinhanh;
			$hinhanh = $hinhanh;
		}
	
		echo $email;
		
		
		$tv = new class_nguoiban();
		$tb = $tv->capnhat($username,$hoten,$ngaysinh,$diachi,$dienthoai,$gioitinh,$hinhanh);
		
		//echo $tb;
		if($tb == true)
			echo "<meta http-equiv=refresh content='0; url=index.php?com=nguoiban&fun=updatethongtin&MaSo=$MaSo&mess=1'/>";
		else
			echo "<meta http-equiv=refresh content='0; url=index.php?com=nguoiban&fun=updatethongtin&MaSo=$MaSo&mess=2'/>";
			
	}
?>

<?php																																					    
	
	$Type = 0;
	
	if(isset($_REQUEST['Type']))
		$Type = $_REQUEST['Type'];
	if ($Type == 1)
		CapNhatVaoCSDL();
	
	HienThiChiTiet();	
	
	
	function HienThiChiTiet()
	{
		$Mess = 0;
		$smg = '';
//		echo $Mess;
		if(isset($_REQUEST['mess']))
			$Mess = $_REQUEST['mess'];
		if ($Mess == 1)
			$smg = "<h3 align='left' style='color:Blue'>Cập Nhật Thành Công</h3>";
		if ($Mess == 2)
			$smg = "<h3 align='left' style='color:Red'>Cập Nhật Thất Bại</h3>";
			
		$tv = new class_nguoiban();
		$row = $tv->chitiet($_SESSION['MaUser']);
	
		//$MaSo = $row['MaSo'];
		$Username= $row['Username'];
		$Passwordcu = $row['Password'];
		$email= $row['Email'];
		$hoten = $row['HoTen'];
		$diachi = $row['DiaChi'];
		$dienthoai = $row['DienThoai'];		
		$gioitinh = $row['GioiTinh'];
		$ngaysinh = $row['NgaySinh'];
		$hinhanh = $row['HinhAnh'];
		$hinhanh="../images/nguoiban/".$hinhanh;
		if(!@file_get_contents($hinhanh))
			$hinhanh = '../images/nguoiban/nopic.gif';
		//	$hinhanh = 'images/thanhvien/nopic2.gif';
		$nam = substr($ngaysinh,0,4);
		$thang = substr($ngaysinh,5,2);
		$ngay = substr($ngaysinh,8);
	
		echo '<form name="form1" id="form1" method="post"><table width="800px" border="0" cellpadding="0px" cellspacing="0px">
		    <tr>
				<td colspan="3" style="color:red" align="center">
				 '.$smg.'
				</td>
			</tr>';
			
		echo "<h2> Thông Tin Tài Khoản </h2>";
		echo "<table class='sample'>
			  <tr>
				<td rowspan='6' ><img src=$hinhanh width='100' height='150' align='middle'></td>
				<td>Họ tên</td>
				<td><input id='HoTenCu' name='HoTenCu' type='hidden' value='$hoten'/>
				<input id='upHoTen' name='upHoTen' type='text' value='$hoten'/></td>
				<td>&nbsp;</td>
			  </tr>
			  <tr>
				<td>Địa Chỉ</td>
				<td><input id='DiaChiCu' name='DiaChiCu' type='hidden' value='$diachi'/>
				<input id='upDiaChi' name='upDiaChi' type='text' value='$diachi'/></td>
				<td>&nbsp;</td>
			  </tr>		  
			 <tr>
				<td>Điện Thoại</td>
				<td><input id='DienThoaiCu' name='DienThoaiCu' type='hidden' value='$dienthoai'/>
				<input id='upDienThoai' name='upDienThoai' type='text' value='$dienthoai'/></td>
				<td><div id='loidienthoai'></div></td>
			  </tr>
			   <tr>
				<td>Giới tính</td>";
				if($gioitinh == 1)
				{
					echo "<td><input id='upGioiTinh' name='upGioiTinh' type='radio' checked='checked' value='Nam'/>Nam &nbsp;
					<input id='upGioiTinh' name='upGioiTinh' type='radio' value='Nu'/>	Nữ</td> ";
				}
				else
				{
					echo "<td><input id='upGioiTinh' name='upGioiTinh' type='radio' value='Nam'/>Nam &nbsp;
					<input id='upGioiTinh' name='upGioiTinh' type='radio' checked='checked' value='Nu'/>Nữ</td> ";
				}
			echo "
				<td>&nbsp;</td>
			  </tr>
			   <tr>
				<td>Ngày sinh</td>
				<td>
					<select name='ngay' id='ngay' >";
						for($i = 1 ; $i<=31 ; $i++)
						{
							if($ngay == $i )
								echo "<option value='$i' selected='selected'>$i</option>";
							else
								echo "<option value='$i'>$i</option>";
						}
					echo "</select>";
					echo "&nbsp;&nbsp;";
					echo "<select name='thang' id='thang' >";
						for( $i = 1 ; $i<=12 ; $i++)
						{
							if($thang == $i )
								echo "<option value='$i' selected='selected'>$i</option>";
							else
								echo "<option value='$i'>$i</option>";
						}					
					echo "</select>";
					echo "&nbsp;&nbsp;";
					echo "<select name='nam' id='nam' >";	
						for($i = date('Y') ; $i>1929 ; $i--)
						{
							if($nam == $i )
								echo "<option value='$i' selected='selected'>$i</option>";
							else
								echo "<option value='$i'>$i</option>";
						}					
					echo "</select>";
				echo "
				</td>
				<td>&nbsp;</td>
			  </tr>
			  <tr>
				<td>Hình Ảnh</td>
				<form name='newad' method='post' enctype='multipart/form-data'  action=''>
				<td><input id='HinhAnhCu' name='HinhAnhCu' type='hidden' value='$hinhanh'/>
				<input id='upHinhAnh' name='upHinhAnh' type='file' value='$hinhanh'/>
				<input name='Submit' type='submit' value='Upload image'>
				</td>
				</form>
				<td>&nbsp;</td>
			  </tr>
			</table>";	
			echo "<br />";
		echo "<input type='Submit' name='Update' value='Cập nhật' onclick='XuLyCapNhatCSDLUser($Username)'>";
	}
?>
	<?php 
		echo '</td></tr></table></form>' ;
	?>
	